package cn.com.guage.dtm.mapping.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.mapping.domain.MappingExcelInfo;
import cn.com.guage.dtm.mapping.service.IMappingExcelInfoService;
import cn.com.guage.dtm.metadata.controller.MdEnvController;
import cn.com.guage.dtm.metadata.domain.MdSys;
import cn.com.guage.dtm.metadata.service.IMdSysService;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 文档信息Controller
 * 
 * @author liujun
 * @date 2021-07-14
 */
@Controller
@RequestMapping("/mapping/excel")
public class MappingExcelInfoController extends BaseController
{
	private static final Logger log = LoggerFactory.getLogger(MappingExcelInfoController.class);
	
    private String prefix = "mapping/excel";

    @Autowired
    private IMappingExcelInfoService mappingExcelInfoService;
    
    @Autowired
    private IMdSysService mdSysService;

    @RequiresPermissions("mapping:excel:view")
    @GetMapping()
    public String excel(ModelMap mmap)
    {
    	MdSys mdSys=new MdSys();
    	mdSys.setSysType("1");
    	List<MdSys> mdSysList = mdSysService.selectMdSysList(mdSys);
    	mmap.put("mdSysList_target", mdSysList);
    	
    	mdSys.setSysType("2");
    	mdSysList = mdSysService.selectMdSysList(mdSys);
    	mmap.put("mdSysList_source", mdSysList);
        return prefix + "/excel";
    }

    /**
     * 查询文档信息列表
     */
    @RequiresPermissions("mapping:excel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MappingExcelInfo mappingExcelInfo)
    {
        startPage();
        List<MappingExcelInfo> list = mappingExcelInfoService.selectMappingExcelInfoList(mappingExcelInfo);
        return getDataTable(list);
    }

    /**
     * 导出文档信息列表
     */
    @RequiresPermissions("mapping:excel:export")
    @Log(title = "文档信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MappingExcelInfo mappingExcelInfo)
    {
        List<MappingExcelInfo> list = mappingExcelInfoService.selectMappingExcelInfoList(mappingExcelInfo);
        ExcelUtil<MappingExcelInfo> util = new ExcelUtil<MappingExcelInfo>(MappingExcelInfo.class);
        return util.exportExcel(list, "文档信息数据");
    }

    /**
     * 新增文档信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文档信息
     */
    @RequiresPermissions("mapping:excel:add")
    @Log(title = "文档信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MappingExcelInfo mappingExcelInfo)
    {
        return toAjax(mappingExcelInfoService.insertMappingExcelInfo(mappingExcelInfo));
    }

    /**
     * 修改文档信息
     */
    @GetMapping("/edit/{excelId}")
    public String edit(@PathVariable("excelId") Long excelId, ModelMap mmap)
    {
        MappingExcelInfo mappingExcelInfo = mappingExcelInfoService.selectMappingExcelInfoById(excelId);
        mmap.put("mappingExcelInfo", mappingExcelInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存文档信息
     */
    @RequiresPermissions("mapping:excel:edit")
    @Log(title = "文档信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MappingExcelInfo mappingExcelInfo)
    {
        return toAjax(mappingExcelInfoService.updateMappingExcelInfo(mappingExcelInfo));
    }

    /**
     * 删除文档信息
     */
    @RequiresPermissions("mapping:excel:remove")
    @Log(title = "文档信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mappingExcelInfoService.deleteMappingExcelInfoByIds(ids));
    }
}
